layui.use(['form','layer','jquery'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer
        $ = layui.jquery;

    //注册按钮
    form.on("submit(register)",function(data){
        var loginId=$("#loginId").val();
        var inputPassword=$("#inputPassword").val();
        var nextInputPassword=$("#nextInputPassword").val();
        if(loginId == "" || loginId==null){
            offset("auto","请输入注册名！","注册提示","确定");
            return false;
        }
        if(inputPassword == "" || inputPassword==null){
            offset("auto","请输入密码！","注册提示","确定");
            return false;
        }
        if(nextInputPassword == "" || nextInputPassword==null){
            offset("auto","请输入确认密码！","注册提示","确定");
            return false;
        }
        if(inputPassword != nextInputPassword){
            offset("auto","两次密码输入不一致！","注册提示","确定");
            return false;
        }
        var url="user/register";
        var params = {
            userName: loginId,
            userPassword: inputPassword
        };
        $(this).text("注册中...").attr("disabled","disabled").addClass("layui-disabled");
        var obj=$(this);
        $.ajax({
            url : url,
            type : 'POST',
            data : params,
            dataType : 'json',
            //contentType : 'application/json',
            success : function(data, status, xhr) {
                if(data.code=="success"){
                    location.href=data.url;
                }else {
                    obj.text("注册").removeAttr("disabled").removeClass("layui-disabled");
                    offset("auto",data.errorMsg,"注册提示","确定");
                }
            },
            Error : function(xhr, error, exception) {
                obj.text("注册").removeAttr("disabled").removeClass("layui-disabled");
                offset("auto",exception.toString(),"注册提示","确定");

            }
        });
        return false;
    })

    //表单输入效果
    $(".loginBody .input-item").click(function(e){
        e.stopPropagation();
        $(this).addClass("layui-input-focus").find(".layui-input").focus();
    })
    $(".loginBody .layui-form-item .layui-input").focus(function(){
        $(this).parent().addClass("layui-input-focus");
    })
    $(".loginBody .layui-form-item .layui-input").blur(function(){
        $(this).parent().removeClass("layui-input-focus");
        if($(this).val() != ''){
            $(this).parent().addClass("layui-input-active");
        }else{
            $(this).parent().removeClass("layui-input-active");
        }
    })
})
